import { UserProfilesAPI } from "@/request/api.js"
export default {
    namespaced: true,
    state: {
        userInfo: {
            nickName: '小小花',
            coin: 123,
            headImg: require('../../assets/img/userImg.f8bbec5e.png'),
        },
        cartTotal: 32
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        initUserInfo(state) {
            state.userInfo = {
                nickName: '小小花',
                coin: 123,
                headImg: require('../../assets/img/userImg.f8bbec5e.png'),
            };
            state.cartTotal = 32
        }
    },
    actions: {
        async asyncUserInfo(context) {
            //1.请求用户信息
            let user = await UserProfilesAPI();
            console.log("用户信息", user.data.data);
            context.commit("changeUserInfo", user.data.data);

        }
    }
}